package io.binghe.seckill.infrastructure.shiro;

import org.apache.shiro.crypto.hash.SimpleHash;

/**
 * @author: Dragon
 * @since: 2024/1/14 14:16
 */
public class CommonsUtils {

    /**
     * 手机号正则校验
     * @param phone
     * @return
     */
    public static boolean phoneRegexCheck(String phone) {
        if(phone.length() != 11) {
            return false;
        }
        return true;
    }

    /**
     * 获取六位数验证码
     * @return
     */
    public static int getCode() {
        return (int)((Math.random()*9+1)*100000);
    }

    /**
     * 使用md5进行加密
     * @param password
     * @param phoneNumber
     * @return
     */
    public static String encryptPassword(String password, String phoneNumber) {
        return String.valueOf(new SimpleHash("MD5", password, phoneNumber, 1024));
    }

}
